<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="店铺查询：">
          <el-input v-model="formInline.shopName" placeholder="请输入店铺名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <el-button type="primary" @click="addBuy">新增评价</el-button>
        <div class="btnBox">
          <el-upload ref="elUpload" class="upload-demo" :action="fileaction" :headers="headers" :data="fileData"
            :limit="1" :show-file-list="false" :on-success="handleFileChange">
            <!-- :file-list="fileList" -->
            <el-button type="primary">批量导入</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </div>
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:customerAvatar="{ scope }">
          <div>
            <el-image v-if="scope.row.customerAvatar != ''" style="width: 50px; height: 50px"
              :src="scope.row.customerAvatar" :preview-src-list="[scope.row.customerAvatar]"></el-image>
          </div>
        </template>
        <template v-slot:image="{ scope }">
          <div style="display: flex;flex-wrap: wrap;">
            <div v-for="(item,index) in scope.row.image" :key="index" style="margin-right: 5px; margin-bottom: 5px;">
              <el-image style="width: 50px; height: 50px" :src="item" :preview-src-list="scope.row.image"></el-image>
            </div>
          </div>
        </template>
        <template v-slot:content="{ scope }">
          <div class="ellipseHide_three ">
            {{scope.row.content}}
          </div>
        </template>
        <template v-slot:isShow="{ scope }">
          <div>
            <span v-if="scope.row.isShow == 1">显示</span>
            <span v-else>隐藏</span>
          </div>
        </template>
        <template v-slot:operate="{ scope }">
          <el-button type="primary" size="small" @click="editJump(scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="delJump(scope.row)">删除</el-button>
          <el-button type="primary" size="small" @click="isShowJump(scope.row)">{{scope.row.isShow == 1?'隐藏':'显示'}}
          </el-button>
        </template>
      </ex-table>
    </div>
    <!-- 添加区域弹窗 -->
    <detail-dialog v-if="detailDialog" :id="editId" :visible.sync="detailDialog" @success="_handleSuccess" />
  </div>
</template>
<script>
  // components
  import {
    shopevaluateList,
    delShopevaluate,
    isShowShopevaluate
  } from "@/api/setting/merchantEvaluation";
  import {
    getToken
  } from "@/utils/auth";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import DetailDialog from "./components/merchantEvaluation/DetailDialog";
  export default {
    name: "BeeTokenSystemH5MerchantEvaluation",
    components: {
      DetailDialog
    },
    mixins: [handlePageMixin],
    data() {
      return {
        fileaction: process.env.VUE_APP_BASE_API + "/merchant/v1/customer/shopevaluate/import",
        headers: {
          'X-Access-Token': "Bearer " + getToken(),
        },
        fileData: {},
        loading: false,
        formInline: {
          shopName: "", //商户名称
        },
        detailDialog: false,
        tableData: [],
        tableColumn: [{
            prop: "shopName",
            label: "评价店铺",
            width: 150
          },
          {
            label: "头像",
            slot: true,
            slotName: "customerAvatar",
            width: 100
          },
          {
            prop: "customerName",
            label: "用户昵称",
          },
          {
            prop: "phoneNumber",
            label: "联系方式",
            width: 120
          },
          {
            slot: true,
            slotName: "content",
            label: "评价内容",
            width: 350
          },
          {
            label: "评价图片",
            slot: true,
            slotName: "image",
            width: 300
          },
          {
            prop: "totalPoints",
            label: "总评分",
          },
          {
            prop: "environmentPoints",
            label: "店铺环境",
          },
          {
            prop: "servicePoints",
            label: "服务态度",
          },
          {
            prop: "createTime",
            label: "评价时间",
            width: 150
          },
          {
            prop: "updateTime",
            label: "编辑时间",
            width: 150
          },
          {
            label: "状态",
            slot: true,
            slotName: "isShow",
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate",
            width: 240,
            fixed: "right",
          },
        ],
        shopId: '',
        editId: '', //编辑id
      };
    },
    created() {},
    mounted() {
      this.getList();
    },
    methods: {
      handleFileChange(res, file) {
        if (res.code == 200) {
          this.reset()
          this.getList();
        } else {
          this.$message.error(res.message);

        }
        this.$refs.elUpload.clearFiles()
      },
      addBuy() {
        //新增
        this.editId = null
        this.detailDialog = true
      },
      editJump(item) {
        //编辑
        this.editId = item.id
        this.detailDialog = true
      },
      // 删除
      delJump(row) {
        this.$confirm("你确定要删除？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
          .then(() => {
            delShopevaluate(row.id)
              .then((res) => {
                const {} = res.result;
                this.$message({
                  message: "删除成功",
                  type: "success",
                  duration: 1500,
                });
                setTimeout(() => {
                  this.getList();
                }, 1000);
              })
              .finally(() => {
                this.loading = false;
              });
          })
          .catch(() => {});
      },
      // 是否隐藏显示
      isShowJump(row) {
        var title = ''
        if (row.isShow == 1) {
          title = '前端隐藏？'
        } else if (row.isShow == 2) {
          title = '前端显示？'
        }
        this.$confirm(title, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          isShowShopevaluate(row.id).then(res => {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
            });
            setTimeout(() => {
              this.getList();
            }, 800);
          })
        }).catch(() => {});

      },
      _handleSuccess(e) {
        //成功回调
        this.reset()
      },
      search() {
        //搜索
        console.log(this.formInline);
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        shopevaluateList(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;
            this.tableData = records;
            this.tableData = this.tableData.map(vo => {
              if (vo.image.length > 0) {
                vo.image = JSON.parse(vo.image)
              }
              return vo
            })
            this.$refs.table.pageOptions.total = total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
    },
  };

</script>
<style lang="scss" scoped>
  .el-card-title {
    font-size: 20px;
  }

  .head {
    //   box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 40px;
  }

  .listBox {
    //   box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .area_box {
    cursor: pointer;
  }

  .area_box:hover {
    color: #1890FF;
  }

  .ellipseHide_three {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }

</style>
